package com.wn.consumer.dead;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author yellow Docter
 * @date 2022 -09-01
 * @desc
 */
@Component
@Slf4j
public class NormalConsumer {

    //创建死信交换机
    //创建死信对象

    /**
     * @param msg
     * @param channel
     * @param message
     * @throws IOException
     * @Argument(name = "x-dead-letter-exchange",value = "exchange-dlx"),
     * 把队列中的消息推送到指定的交换机中
     *
     * Dead letter routing key(x-dead-letter-routing-key)：将删除的消息推送到指定交换机的指定路由键的队列中去,
     * <p>
     * Message TTL(x-message-ttl)：设置队列中的所有消息的生存周期(统一为整个队列的所有消息设置生命周期),
     */
//    @RabbitListener(
//            bindings = @QueueBinding(
//                    value = @Queue(name = "normal-queue",
//                            arguments = {      //队列的属性
//                                    @Argument(name = "x-dead-letter-exchange", value = "exchange-dead"),
//                                    @Argument(name = "x-dead-letter-routing-key", value = "dead.to.queue"),
//                                    @Argument(name = "x-message-ttl", value = "100000", type = "java.lang.Long")
//                            }
//                    ),
//                    exchange = @Exchange(
//                            name = "exchange-normal",
//                            type = ExchangeTypes.DIRECT
//                    ),
//                    key = "zhangsan"
//            )
//    )
//    public void deadConsumer(String msg, Channel channel, Message message) throws IOException {
//
//        channel.basicReject(
//                message.getMessageProperties().getDeliveryTag(),
//                false
//        );
////        log.info("我是普通的消费者,我消息了消息:{}",msg);
//    }

}
